package com.sskj.gcc.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.gcc.http.HttpConfig;
import com.sskj.gcc.ui.activity.PwdForgetActivity;
import com.sskj.lib.http.JsonCallBack;


public class PwdForgetActivityPresenter extends BasePresenter<PwdForgetActivity> {


    public void setPwdWithCode(String account, String code, String pwd) {

    }

    /**
     * 重置登录密码
     *
     * @param email  邮箱号
     * @param phone 手机号
     * @param opwd   密码
     * @param opwd1  确认登录密码
     * @param code   验证码
     * @return
     */
    public void resetLoginPwd(String email,String phone, String opwd, String opwd1, String code) {
        httpService.resetLoginPwd(email, phone,opwd, opwd1, code).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getCode() == HttpConfig.OK) {
                    mView.resetPwdSuccess();
                }
            }
        });
    }

    public void sendCode(String account,String mcode) {
        if (account.contains("@")) {
            sendEmail(account);
        } else {
            sendSms(account,mcode, "2");
        }
    }

    /**
     * 发送验证码（注册）
     *
     * @param mobile 手机号
     * @param type   1注册 （2 重置 3 安全验证 4 资金密码设置 5 提币）
     * @return
     */
    public void sendSms(String mobile,String mcode, String type) {

        httpService.sendSms(mobile,mcode, type).execute(callback);
    }

    JsonCallBack<HttpData> callback = new JsonCallBack<HttpData>(this) {
        @Override
        public void onSuccess(Response<HttpData> response) {
            HttpData httpData = response.body();
            if (httpData.getCode() == HttpConfig.OK) {
                ToastUtil.showShort(httpData.getMsg());
                mView.sendCheckCodeSuccess();
            } else {
                ToastUtil.showShort(httpData.getMsg());
                mView.sendCheckCodeFail();
            }
        }

        @Override
        public void onError(Response<HttpData> response) {
            mView.sendCheckCodeFail();

            super.onError(response);
        }
    };

    /**
     * 发送邮件
     *
     * @param email 邮箱号
     * @return
     */
    public void sendEmail(String email) {
        httpService.sendEmail(email,"2").execute(callback);
    }


}
